package com.erp.myAdapter

import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.BaseAdapter
import android.widget.LinearLayout
import android.widget.TextView
import com.erp.R
import com.erp.bean.ProdyctionClientBean
import com.erp.util.Myutil
import kotlinx.android.synthetic.main.lv_wuliao_item.view.*

/**
 * Created by Administrator on 2016/12/30/030.
 * 作者：刘洋
 */
class WuliaoAdapter(private val mcontext: Context, private var mlist: List<ProdyctionClientBean.wuliaomingxi>) : BaseAdapter() {
    private val minflater: LayoutInflater = LayoutInflater.from(mcontext)
    private var isitem = -1

    override fun getCount(): Int {
        return mlist.size
    }

    override fun getItem(position: Int): Any {
        return mlist[position]
    }

    override fun getItemId(position: Int): Long {
        return position.toLong()
    }

    override fun getView(position: Int, convertView: View?, parent: ViewGroup?): View {
        var v :View
        val vh: ViewHolder
        if (convertView == null) {
            v = minflater.inflate(R.layout.lv_wuliao_item, null)
            vh = ViewHolder(v)
            v.tag = vh
        } else {
            v = convertView
            vh = convertView.tag as ViewHolder
        }
        if (isitem == position) {
            vh.llMWuliao.visibility = View.VISIBLE
            vh.llWuliao.setBackgroundResource(R.color.gainsboro)
        } else {
            vh.llMWuliao.visibility = View.GONE
            vh.llWuliao.setBackgroundResource(R.color.white)
        }
        var wuliaomingxi = ProdyctionClientBean.wuliaomingxi()
        wuliaomingxi = mlist[position]
        Myutil.settv(wuliaomingxi.c_cnum, vh.tvCCnum)
        Myutil.settv(wuliaomingxi.p_pnum, vh.tvPPnum)
        Myutil.settv(wuliaomingxi.mc1_mark, vh.tvMc1Mark)
        Myutil.settv(wuliaomingxi.mc2_mark, vh.tvMc2Mark)
        Myutil.settv(wuliaomingxi.mc_2_name, vh.tvMc2Name)
        Myutil.settv(wuliaomingxi.m_name, vh.tvMName)
        Myutil.settv(wuliaomingxi.es_type, vh.tvEsType)
        Myutil.settv(wuliaomingxi.m_size, vh.tvMSize)
        Myutil.settv(wuliaomingxi.color_color, vh.tvColorColor)
        Myutil.settv(wuliaomingxi.color_code, vh.tvColorCode)
        Myutil.settv(wuliaomingxi.m_counts, vh.tvMCounts)
        Myutil.settv(wuliaomingxi.unit_unit, vh.tvUnitUnit)
        Myutil.settv(wuliaomingxi.m_remark, vh.tvMRemark)
        Myutil.settv(wuliaomingxi.m_code, vh.tvMCode)
        Myutil.settv(wuliaomingxi.area_num, vh.tvAreaNum)
        Myutil.settv(wuliaomingxi.m_square, vh.tvMSquare)
        Myutil.settv(wuliaomingxi.m_material_num, vh.tvMMaterialNum)
        Myutil.settv(wuliaomingxi.m_thickness, vh.tvMThickness)
        Myutil.settv(wuliaomingxi.mb_weihao, vh.tvMbWeihao)
        Myutil.settv(wuliaomingxi.mb_batch, vh.tvMbBatch)
        Myutil.settv(wuliaomingxi.m_category, vh.tvMCategory)
        Myutil.settv(wuliaomingxi.fangxiang,vh.tvFangXiang)
        Myutil.settv(wuliaomingxi.finished_size,vh.tvFinishedSize)
        Myutil.settv(wuliaomingxi.slot_name,vh.tvSlotName)
        Myutil.settv(wuliaomingxi.mm_menjiaokong,vh.tvMenJiaoKong)
        if (wuliaomingxi.oo_onum == "" && wuliaomingxi.cqi_name == "" && wuliaomingxi.cqi_mark == "" && wuliaomingxi.co_shouliren == "" && wuliaomingxi.co_shouli_time == "" &&
                wuliaomingxi.cor_name == "" && wuliaomingxi.ci_name == "") {
            vh.llCdan.visibility = View.GONE
        } else {
            Myutil.settv(wuliaomingxi.oo_onum, vh.tvOoOnum)
            Myutil.settv(wuliaomingxi.cqi_name, vh.tvCqiName)
            Myutil.settv(wuliaomingxi.cqi_mark, vh.tvCqiMark)
            Myutil.settv(wuliaomingxi.co_shouliren, vh.tvCoShouliren)
            Myutil.settv(Myutil.getdata(wuliaomingxi.co_shouli_time), vh.tvCoShouliTime)
            Myutil.settv(wuliaomingxi.cor_name, vh.tvCorName)
            Myutil.settv(wuliaomingxi.ci_name, vh.tvCiName)
        }
        return v
    }


    fun isitem(position: Int) {
        if (isitem == position) {
            isitem = -1
        } else {
            isitem = position
        }
        notifyDataSetChanged()
    }

    fun Allniotifi(list: List<ProdyctionClientBean.wuliaomingxi>) {
        this.mlist = list
        notifyDataSetChanged()
    }

    internal class ViewHolder(v: View) {
        var tvCCnum: TextView = v.tv_c_cnum
        var tvMName: TextView = v.tv_m_name
        var tvMSize: TextView = v.tv_m_size
        var tvMCounts: TextView = v.tv_m_counts
        var tvColorCode: TextView = v.tv_color_code
        var llBaojiandan: LinearLayout = v.ll_baojiandan
        var tvPPnum: TextView = v.tv_p_pnum
        var tvMc2Name: TextView = v.tv_mc_2_name
        var tvMMaterialNum: TextView = v.tv_m_material_num
        var tvMc2Mark: TextView = v.tv_mc2_mark
        var tvEsType: TextView = v.tv_es_type
        var tvUnitUnit: TextView = v.tv_unit_unit
        var tvColorColor: TextView = v.tv_color_color
        var tvMc1Mark: TextView = v.tv_mc1_mark
        var tvMRemark: TextView = v.tv_m_remark
        var tvAreaNum: TextView = v.tv_area_num
        var tvMSquare: TextView = v.tv_m_square
        var tvMThickness: TextView = v.tv_m_thickness
        var tvMbWeihao: TextView = v.tv_mb_weihao
        var tvMbBatch: TextView = v.tv_mb_batch
        var tvMCategory: TextView = v.tv_m_category
        var tvMCode: TextView = v.tv_m_code
        var tvOoOnum: TextView = v.tv_oo_onum
        var tvCqiName: TextView = v.tv_cqi_name
        var tvCqiMark: TextView = v.tv_cqi_mark
        var tvCoShouliren: TextView = v.tv_co_shouliren
        var tvCoShouliTime: TextView = v.tv_co_shouli_time
        var tvCorName: TextView = v.tv_cor_name
        var tvCiName: TextView = v.tv_ci_name
        var llCdan: LinearLayout = v.ll_cdan
        var llMWuliao: LinearLayout = v.ll_m_wuliao
        var llWuliao : LinearLayout = v.llWuliao
        var tvFangXiang: TextView = v.tv_fangxiang
        var tvMenJiaoKong: TextView = v.tv_mm_menjiaokong
        var tvSlotName: TextView = v.tv_slot_name
        var tvFinishedSize: TextView = v.tv_finished_size
    }
}
